package cn.tedu.adminsystem.webapi.controller;

import cn.tedu.community.commons.pojo.returnHome.dto.UpdateResponseDTO;
import cn.tedu.community.commons.pojo.returnHome.vo.ReturnHomeVO;
import cn.tedu.community.commons.restful.JsonPage;
import cn.tedu.community.commons.restful.JsonResult;
import cn.tedu.epidemic.service.ReturnHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Pattern;

@Validated
@RestController
@Slf4j
@RequestMapping("/returnHome")
@Api(tags = "返乡报备控制器")
public class ReturnHomeController {

    @DubboReference
    private ReturnHomeService dubboService;

    @ApiOperation("根据返乡报备id提交审核回复")
    @PostMapping("/{id:[0-9]+}/updateResponse")
    public JsonResult<Void> updateResponse(@PathVariable Long id, @Valid UpdateResponseDTO responseDTO) {
        log.debug("开始执行根据返乡报备id提交审核回复，数据是：{},{}", id, responseDTO);
        dubboService.updateResponse(id, responseDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{auditedOrNot:[0-1]}/{page:[0-9]+}/{pageSize:[0-9]+}")
    @ApiOperation("查询分页已审核或未审核返乡报备列表,auditedOrNot==0'未审核'、1'已审核'")
    public JsonResult<JsonPage<ReturnHomeVO>> ListAuditedOrNot(@PathVariable Integer auditedOrNot, @PathVariable Integer page,
                                                               @PathVariable Integer pageSize) {
        log.debug("查询分页已审核或未审核返乡报备列表，审核码是：{}，page是：{}，pageSize是：{}", auditedOrNot, page, pageSize);
        JsonPage<ReturnHomeVO> homeVOJsonPage = dubboService.ListAuditedOrNot(auditedOrNot, page, pageSize);
        log.debug("查询分页已审核或未审核返乡报备列表，数据是：{}", homeVOJsonPage);
        return JsonResult.ok(homeVOJsonPage);
    }
}
